home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Graphics Programming (2nd Edition)
/
Visual Basic Graphics Programming 2nd Edition.iso
/
OldSrc
/
CH1
/
SRC
/
RUBBRBOX.FRM
< prev
next >
Wrap
Text File
|
1995-12-15
|
3KB
|
115 lines
VERSION 4.00
Begin VB.Form RubberForm
AutoRedraw = -1 'True
Caption = "Rubberband Boxes"
ClientHeight = 4140
ClientLeft = 1140
ClientTop = 1800
ClientWidth = 6690
Height = 4830
Left = 1080
LinkTopic = "Form1"
ScaleHeight = 4140
ScaleWidth = 6690
Top = 1170
Width = 6810
Begin VB.Menu mnuFile
Caption = "&File"
Begin VB.Menu mnuFileExit
Caption = "E&xit"
End
End
End
Attribute VB_Name = "RubberForm"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
Dim Rubberbanding As Boolean
Dim OldMode As Integer
Dim OldStyle As Integer
Dim FirstX As Single
Dim FirstY As Single
Dim LastX As Single
Dim LastY As Single
' ***********************************************
' Start rubberbanding.
' ***********************************************
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Let MouseMove know we are rubberbanding.
Rubberbanding = True
' Save values so we can restore them later.
OldMode = DrawMode
OldStyle = DrawStyle
DrawMode = vbInvert
DrawStyle = vbDot
' Save the starting coordinates.
FirstX = X
FirstY = Y
' Draw the initial rubberband box.
LastX = X
LastY = Y
Line (FirstX, FirstY)-(LastX, LastY), , B
End Sub
' ***********************************************
' Continue rubberbanding.
' ***********************************************
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' If we are not rubberbanding, do nothing.
If Not Rubberbanding Then Exit Sub
' Erase the previous rubberband box.
Line (FirstX, FirstY)-(LastX, LastY), , B
' Draw the new rubberband box.
LastX = X
LastY = Y
Line (FirstX, FirstY)-(LastX, LastY), , B
End Sub
' ***********************************************
' Stop rubberbanding.
' ***********************************************
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim oldfill As Integer
Dim oldcolor As Long
' If we are not rubberbanding, do nothing.
If Not Rubberbanding Then Exit Sub
' We are no longer rubberbanding.
Rubberbanding = False
' Erase the previous rubberband box.
Line (FirstX, FirstY)-(LastX, LastY), , B
' Restore the original DrawMode and DrawStyle.
DrawMode = OldMode
DrawStyle = OldStyle
' Fill the final box with a random color.
oldfill = FillStyle
oldcolor = FillColor
FillStyle = vbSolid
FillColor = QBColor(Int(Rnd * 16))
Line (FirstX, FirstY)-(LastX, LastY), , B
FillStyle = oldfill
FillColor = oldcolor
End Sub
Private Sub mnuFileExit_Click()
Unload Me
End Sub